Save cleaner V 2.05 beta. This tool is open source*, you can use it for your own projects as you wish.

*Savetool.exe is a RosAsm pe file, so source is embedded in it and it can be modified and compiled with RosAsm, available at:
https://code.google.com/p/rosasm2052f/downloads/list


Little updated readme file for v 2.00+.

May contain a bad english and errors.

#############################################################################

FOR A BASIC SCRIPT CLEANING:

1. Click open, choose a save game file.

2. Click "FixScriptInstances", it removes all orphan script instances.

3. (Optional)
   Click a "Delete all #" button to remove all the scripts, that are detected as orphan.
   It can take a while if there is lots of them.

   (Works well for vanilla and the dlc's, but can wrongly see some other mods scripts as orphan.
   If it finds orphan scripts again, after save is saved again in game,
   then those are quite surely detected wrong.)

4. Save the cleaned save using save as or save button.

   NOTE: "save as" doesn't create a backup for you, even if Auto backup is ticked.
   Backups are named as "backup-date_time.ess" and "backup-date_time.skse"

5.
   Load a save into game, and save it again. Now it should be fully cleaned.
   Re-saving removes script names etc.

6.
   Here's other cleaning buttons too: "Clean other" and one for formlists "Clean formlist".
   And of course you can look other items at tree,
   these are name as "null" or formid field is 00000000 (usually first number after name).
   Scripts that are quessed to be orphans, have mark #-> before its name.


Other way:
 If you want to keep some scripts, that auto detection is marked as orphans, (ones begin at #)
 just manually delete what you wish to.

#############################################################################


OTHER BUTTONS:

Scripts:

 Inc.forms:
  Removes forms linked on selected script instances, when you remove that script. Does nothing on orphan script instances.
  Be careful with it, if there is, say 00000014 id in some instance, it removes your player..

 Del. broken actives:
  Removes all active scripts having variables pointing to removed scripts. You can use this after removed scripts manually,
  or after cleaning.

 Clean other:
  Cleans some other orphan items.
  In current version, array7 and visited worldspace array is cleaned.


Forms/mods:

 Mod editor:
  Opens the mod editor dialog.
  Delete mod forms: ( eg. have installed dungeon mod, killed all creatures on it, and want play it again. Otherwise quite useless)
  Removes all selected plugins forms from save. Can be used for reset some plugin its default state. However, mods can have
  other data, and those aren't reset. So best to use it for non quest/scripted mods only, or troubleshooting.

 Clean formlists:
  Removes all null refs at formlists.

 Reset havok:
  Remove all forms that have a havok_moved flag, or havok_moved + cell changed flags.



Forms:

  Delete, save or load a saved form. Can be used to tranfer things between different saves.
  Edit button works for formlist types only.



#############################################################################

Information used:
 http://www.uesp.net/wiki/Tes5Mod:Save_File_Format


Orphan instance detection (FixScriptInstances) works as if the script instance RefId is 0, instance is orphan.

 http://www.uesp.net/wiki/Tes5Mod:Save_File_Format/Papyrus#ScriptInstance
 0 RefId instances seems to be not present on saves that are used without uninstalling a mod.


Orphan script detection works as if script type is 0, script is quessed to be orphan and marked as #.
 Some vanilla scripts (3 of them: Alias, ActiveMagicEffect and Form) type is always 0, and they are filtered out of orphan list.

 http://www.uesp.net/wiki/Tes5Mod:Save_File_Format/Papyrus#Script





